<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>t_alloc</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4>NAME</h4><blockquote>
t_alloc - allocate a library structure
</blockquote><h4>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="xti.h.html">xti.h</a>&gt;

void *t_alloc(
    int fd,
    int struct_type,
    int fields)
</code>
</pre>
</blockquote><h4>DESCRIPTION</h4><blockquote>
<pre>
<P><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Parameters</b>
<th align=center><b>Before call</b>
<th align=center><b>After call</b>
<tr valign=top><td align=left>fd
<td align=center>x
<td align=center>/
<tr valign=top><td align=left>struct_type
<td align=center>x
<td align=center>/
<tr valign=top><td align=left>fields
<td align=center>x
<td align=center>/
</table>
</pre>
<p>
The
<i>t_alloc()</i>
function dynamically allocates memory for the
various transport function argument structures as specified below.
This function will allocate memory for the specified structure, and
will also allocate memory for buffers referenced by the structure.
<p>
The structure to allocate is specified by
<I>struct_type</I>
and must be one of the following:
<pre>
<code>
T_BIND       struct     t_bind
T_CALL       struct     t_call
T_OPTMGMT    struct     t_optmgmt
T_DIS        struct     t_discon
T_UNITDATA   struct     t_unitdata
T_UDERROR    struct     t_uderr
T_INFO       struct     t_info
</code>
</pre>
<p>
where each of these structures may subsequently be
used as an argument to one or more transport functions.
<p>
Each of the above structures, except T_INFO,
contains at least one field of type
<B>struct</B>
<B>netbuf</B>.
For each field of this type, the user may specify that
the buffer for that field should be allocated as well.
The length of the buffer allocated will be equal to or greater than
the appropriate size as returned in the
<I>info</I>
argument of
<i><a href="t_open.html">t_open()</a></i>
or
<i><a href="t_getinfo.html">t_getinfo()</a></i>.
The relevant fields of the
<I>info</I>
argument are described in the following list.
The
<I>fields</I>
argument specifies which buffers to allocate, where the argument is the
bitwise-or of any of the following:
<dl compact>

<dt>T_ADDR<dd>The
<I>addr</I>
field of the
<B>t_bind</B>,
<B>t_call</B>,
<B>t_unitdata</B>
or
<B>t_uderr</B>
structures.

<dt>T_OPT<dd>The
<I>opt</I>
field of the
<B>t_optmgmt</B>,
<B>t_call</B>,
<B>t_unitdata</B>
or
<B>t_uderr</B>
structures.

<dt>T_UDATA<dd>The
<I>udata</I>
field of the
<B>t_call</B>,
<B>t_discon</B>
or
<B>t_unitdata</B>
structures.

<dt>T_ALL<dd>All relevant fields of the given structure. Fields which are not supported
by the transport provider specified by
<I>fd</I>
will not be allocated.

</dl>
<p>
For each relevant field specified in
<I>fields</I>,
<i>t_alloc()</i>
will allocate memory for the buffer associated with the field,
and initialise the
<I>len</I>
field to zero and the
<I>buf</I>
pointer
and
<I>maxlen</I>
field accordingly.
Irrelevant or unknown values passed in fields are ignored.
Since
the length of the buffer allocated will be based on the same size
information that is returned to the user on a call to
<i><a href="t_open.html">t_open()</a></i>
and
<i><a href="t_getinfo.html">t_getinfo()</a></i>,
<I>fd</I>
must refer to the transport endpoint through which the newly
allocated structure will be passed.
In the case where a T_INFO structure is to be allocated,
<I>fd</I>
may be set to any value.
In this way the appropriate
size information can be accessed.
If the size value associated with any specified field is 
T_INVALID (see 
<i><a href="t_open.html">t_open()</a></i>
or 
<i><a href="t_getinfo.html">t_getinfo()</a></i>),
<i>t_alloc()</i>
will be unable to determine the size of the buffer to 
allocate and will fail, setting 
<I>t_errno</I>
to [TSYSERR] and 
<I>errno</I>
to [EINVAL]. If the size value associated with
any specified field is T_INFINITE (see 
<i><a href="t_open.html">t_open()</a></i>
or
<i><a href="t_getinfo.html">t_getinfo()</a></i>),
then the behaviour of 
<i>t_alloc()</i>
is implementation-defined.
For any field not specified in
<I>fields</I>,
<I>buf</I>
will be set to the null pointer
and
<I>len</I>
and
<I>maxlen</I>
will be set to zero.
<p>
The pointer returned if the allocation succeeds is
suitably aligned so that it can be assigned to a pointer
to any type of object and then used to access such an
object or array of such objects in the space allocated.
<p>
Use of
<i>t_alloc()</i>
to allocate structures will help ensure the compatibility of user
programs with future releases of the transport interface functions.
</blockquote><h4>VALID STATES</h4><blockquote>
ALL - apart from T_UNINIT
</blockquote><h4>ERRORS</h4><blockquote>
On failure,
<I>t_errno</I>
is set to one of the following:
<dl compact>

<dt>[TBADF]<dd><B>struct_type</B>
is other than T_INFO and
the specified file descriptor does not refer to a transport endpoint.

<dt>[TNOSTRUCTYPE]<dd>Unsupported
<I>struct_type</I>
requested.
This can include a request for a structure type which is inconsistent with
the transport provider type
specified, that is, connection-mode or connectionless-mode.

<dt>[TPROTO]<dd>This error indicates that a communication problem has been detected between
XTI and the transport provider for which there is no other suitable XTI
error
<I>(t_errno)</I>.

<dt>[TSYSERR]<dd>A system error has occurred during execution of this function.

</dl>
</blockquote><h4>RETURN VALUE</h4><blockquote>
On successful completion,
<i>t_alloc()</i>
returns a pointer to the newly allocated structure.
On failure, a null pointer is returned.
</blockquote><h4>SEE ALSO</h4><blockquote>
<i><a href="t_free.html">t_free()</a></i>,
<i><a href="t_getinfo.html">t_getinfo()</a></i>,
<i><a href="t_open.html">t_open()</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
